﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace Lilium.Web.Mvc.Configuration
{
	public abstract class ScriptResourceLibraryElement: ConfigurationElement
	{
		#region public string ContentType

		private const string ContentTypePropertyName = "contentType";

		[ConfigurationPropertyAttribute(ContentTypePropertyName)]
		public string ContentType { [DebuggerNonUserCodeAttribute] get { return (string)base[ContentTypePropertyName]; } [DebuggerNonUserCodeAttribute] set { base[ContentTypePropertyName] = value; } }

		#endregion

		#region public OutputCacheConfigurationElement OutputCache

		private const string OutputCachePropertyName = "outputCache";

		[ConfigurationPropertyAttribute(OutputCachePropertyName)]
		public OutputCacheConfigurationElement OutputCache { [DebuggerNonUserCodeAttribute] get { return (OutputCacheConfigurationElement)base[OutputCachePropertyName]; } [DebuggerNonUserCodeAttribute] set { base[OutputCachePropertyName] = value; } }

		#endregion

		#region public string Name

		private const string NamePropertyName = "name";

		[ConfigurationPropertyAttribute(NamePropertyName, IsRequired = true, IsKey = true)]
		public string Name { get { return (string)base[NamePropertyName]; } set { base[NamePropertyName] = value; } }

		#endregion

		#region public ScriptResourceElementCollection Resources

		private const string ResourcesPropertyName = "resources";

		[ConfigurationPropertyAttribute(ResourcesPropertyName)]
		public ScriptResourceElementCollection Resources
		{
			[DebuggerNonUserCodeAttribute]
			get
			{
				var resources = (ScriptResourceElementCollection)base[ResourcesPropertyName];
				if (resources != null)
					resources.ScriptResourceLibrary = this;
				return resources;
			}
		}

		#endregion

		public abstract ScriptResourceLibrary GetScriptResourceLibrary();

		protected internal OutputCachePolicy GetCachePolicy()
		{
			return OutputCache.GetCachePolicy();
		}

		protected IEnumerable<ScriptResource> GetScriptResources()
		{
			return Resources.Select(e => e.GetScriptResource());
		}
	}
}